package com.company.笔试.TreeMapAndLinkedHashMap;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @Classname MyTreeMap
 * @Description TODO
 * @Date 2021/7/30 21:36
 * @Created by ylr
 */
public class MyTreeMap {
    public static void main(String[] args) {
//        TreeMap<Integer, Integer> treeMap = new TreeMap<>(new Comparator<Integer>() {
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                return o1-o2;
//            }
//        });
        TreeMap<Integer, Integer> treeMap = new TreeMap<>();
        treeMap.put(2, 1);
        treeMap.put(5, 2);
        treeMap.put(1, 3);
        Iterator<Map.Entry<Integer, Integer>> iterator = treeMap.entrySet().iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("------------------");
        System.out.println(treeMap);


    }
}
